﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace IOBusiness
{
    public static class clsBSFileUpload
    {
        public static string SaveFile(System.Web.UI.WebControls.FileUpload fu, string url)
        {
            try
            {
                string filename = "";
                if (fu.HasFile)
                {
                    FileInfo finfo = new FileInfo(url + fu.FileName);
                    finfo = new FileInfo(url + fu.FileName);
                    int dem = 0;
                    filename = fu.FileName;
                    while (finfo.Exists)
                    {
                        dem++;
                        filename = dem.ToString() + fu.FileName;
                        finfo = new FileInfo(url + filename);
                    }
                    fu.SaveAs(url + filename);

                }
                return filename;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public static void DeleteFile(string url)
        {
            try
            {
                FileInfo finfo = new FileInfo(url);
                if (finfo.Exists)
                    File.Delete(url);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
